<?php

namespace apiend\modules\educater\models;

use Yii;
use yii\data\ActiveDataProvider;

/**
 * 校长快速检索模型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class PresidentSearch extends \common\models\teacher\Teacher {

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['id', 'number', 'name', 'mobile', 'gender', 'grade_id', 'status'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        $labels = parent::attributeLabels();
        $labels['category_id'] = '教学分类';
        $labels['number'] = '校长编号';
        return $labels;
    }

    //搜索
    public function search($params) {
        $query = static::find()
        ->where(['role_id' => static::ROLE_ID_PRESIDENT]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query
        ]);
        // 从参数的数据中加载过滤条件，并验证
        $this->load($params);

        if (!$this->validate()) {
            $this->tips('error', print_r($this->errors, true));
            return $dataProvider;
        }

        // 增加过滤条件来调整查询对象
        $query->andFilterWhere(['like', 'number', $this->number]);
        $query->andFilterWhere(['like', 'name', $this->name]);
        $query->andFilterWhere(['like', 'mobile', $this->mobile]);
        $query->andFilterWhere(['gender' => $this->gender]);
        $query->andFilterWhere(['grade_id' => $this->grade_id]);
        $query->andFilterWhere(['status' => $this->status]);

        return $dataProvider;
    }

}
